package com.mstarc.app.mnfc.mstarcApiUtils;

import android.util.Log;

import mstarc_os_api.mstarc_os_api_msg;

/**
 * Created by qdyouke01 on 2017/7/3.
 */

public class WriteSEIDUtil {
    /**
     * @author: cuijianwei
     * @time: 2017/6/23 13:19
     * @desc: 写入SEID
     **/
    public static int write_seid(mstarc_os_api_msg m_api_msg, int[] seid) {
        int ret = -1;
        int[] response;

        int[] apdu_write_seid = new int[seid.length + 7];

        apdu_write_seid[0] = 0x80;
        apdu_write_seid[1] = 0xE2;
        apdu_write_seid[2] = 0x80;
        apdu_write_seid[3] = 0x00;
        apdu_write_seid[4] = seid.length + 2;
        apdu_write_seid[5] = 0x44;
        apdu_write_seid[6] = seid.length;

        System.arraycopy(seid, 0, apdu_write_seid, 7, seid.length);

        response = ApduUtil.apdu(m_api_msg, apdu_write_seid);
        if (response.length >= 2) {
            if (response[response.length - 2] == 0x90 && response[response.length - 1] == 0x00) {
                ret = 0;
            } else {
                ret = 1;
            }

            for (int i = 0; i < response.length; i++) {
                Log.i("yhy", "response[" + i + "] = 0x" + Integer.toHexString(response[i]));
            }
        }

        return ret;
    }
}
